﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for TAMoreDetailLibertyDB
/// </summary>
/// 
namespace CE.TravelInsurance
{
    public class TAMoreDetailLibertyDB
    {
        public TAMoreDetailLibertyDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(TAMoreDetailLiberty tamoredetailliberty)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocTAMoreDetailInsertUpdateSingleItemLiberty]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CETAMoreDetailId", tamoredetailliberty.cetaMoreDetailId);
            _sPara.Add("@CETAInsId", tamoredetailliberty.cetaInsId);
            _sPara.Add("@CETAID", tamoredetailliberty.cetaId);
            _sPara.Add("@ProviderCompanyId", tamoredetailliberty.ProviderCompanyId);
            _sPara.Add("@Name", tamoredetailliberty.Name);
            _sPara.Add("@PostalCode", tamoredetailliberty.PostalCode);
            _sPara.Add("@UnitNo", tamoredetailliberty.UnitNo);
            _sPara.Add("@HomeNo", tamoredetailliberty.HomeNo);
            _sPara.Add("@Address", tamoredetailliberty.Address);
            _sPara.Add("@NRICNo", tamoredetailliberty.NRICNo);
            _sPara.Add("@Nationality", tamoredetailliberty.Nationality);
            _sPara.Add("@MobileNo", tamoredetailliberty.MobileNo);
            _sPara.Add("@HomePhoneNo", tamoredetailliberty.HomePhoneNo);
            _sPara.Add("@OfficePhoneNo", tamoredetailliberty.OfficePhoneNo);
            _sPara.Add("@FaxNo", tamoredetailliberty.FaxNo);
            _sPara.Add("@Gender", tamoredetailliberty.Gender);
            _sPara.Add("@DOB", tamoredetailliberty.DOB);
            _sPara.Add("@MaritalStatus", tamoredetailliberty.MaritalStatus);
            _sPara.Add("@Occupation", tamoredetailliberty.Occupation);
            _sPara.Add("@EmpName", tamoredetailliberty.EmpName);
            _sPara.Add("@EmployersBusiness", tamoredetailliberty.EmployersBusiness);
            _sPara.Add("@PlanName", tamoredetailliberty.PlanName);
            _sPara.Add("@PlanType", tamoredetailliberty.PlanType);
            _sPara.Add("@TripType", tamoredetailliberty.TripType);
            _sPara.Add("@CoverageLevel", tamoredetailliberty.CoverageLevel);
            _sPara.Add("@Country", tamoredetailliberty.Country);
            _sPara.Add("@Area", tamoredetailliberty.Area);
            _sPara.Add("@Duration", tamoredetailliberty.Duration);
            _sPara.Add("@StartDate", tamoredetailliberty.StartDate);
            _sPara.Add("@EndDate", tamoredetailliberty.EndDate);
            _sPara.Add("@ChildAge", tamoredetailliberty.ChildAge);
            _sPara.Add("@AdultAge", tamoredetailliberty.AdultAge);
            _sPara.Add("@NoOfTraveller", tamoredetailliberty.NoOfTraveller);
            _sPara.Add("@TotalPremium", tamoredetailliberty.TotalPremium);
            _sPara.Add("@PamentType", tamoredetailliberty.PamentType);            
            _sPara.Add("@RefCEUserId", tamoredetailliberty.RefCEUserId);
            _sPara.Add("@ViewedDetailId", tamoredetailliberty.ViewedDetailId);
            _sPara.Add("@Status", tamoredetailliberty.Status);
            _sPara.Add("@Info1", tamoredetailliberty.Info1);
            _sPara.Add("@Info2", tamoredetailliberty.Info2);
            _sPara.Add("@Info3", tamoredetailliberty.Info3);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public TAMoreDetailLiberty GetTAMoreDetail(Int64 TAId, Int64 CEUserId)
        {
            TAMoreDetailLiberty _tamoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocTAMoreDetailSelectSingleItemLiberty";

            SortedList _spara = new SortedList();
            _spara.Add("@CETAid", TAId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _tamoredetail = new TAMoreDetailLiberty();
                    _tamoredetail = FillDataRecord(_dt);
                }
            }
            return _tamoredetail;
        }

        private TAMoreDetailLiberty FillDataRecord(DataTable myDataTable)
        {
            TAMoreDetailLiberty myTAMoreDetail = new TAMoreDetailLiberty();
            myTAMoreDetail.cetaMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["cetaMoreDetailId"].ToString());
            myTAMoreDetail.cetaInsId = Convert.ToInt64(myDataTable.Rows[0]["cetaInsId"].ToString());
            myTAMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myTAMoreDetail.cetaId = Convert.ToInt64(myDataTable.Rows[0]["cetaId"].ToString());
            myTAMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            myTAMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myTAMoreDetail.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
            myTAMoreDetail.HomeNo = myDataTable.Rows[0]["HomeNo"].ToString();
            myTAMoreDetail.Address = myDataTable.Rows[0]["Address"].ToString();
            myTAMoreDetail.NRICNo = myDataTable.Rows[0]["NRICNo"].ToString();
            myTAMoreDetail.Nationality = myDataTable.Rows[0]["Nationality"].ToString();            
            myTAMoreDetail.MobileNo = myDataTable.Rows[0]["MobileNo"].ToString();
            myTAMoreDetail.HomePhoneNo = myDataTable.Rows[0]["HomePhoneNo"].ToString();
            myTAMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            myTAMoreDetail.FaxNo = myDataTable.Rows[0]["FaxNo"].ToString();
            myTAMoreDetail.Gender = myDataTable.Rows[0]["Gender"].ToString();
            myTAMoreDetail.DOB = Convert.ToDateTime(myDataTable.Rows[0]["DOB"].ToString());
            myTAMoreDetail.MaritalStatus = myDataTable.Rows[0]["MaritalStatus"].ToString();
            myTAMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myTAMoreDetail.EmpName = myDataTable.Rows[0]["EmpName"].ToString();
            myTAMoreDetail.EmployersBusiness = myDataTable.Rows[0]["EmployersBusiness"].ToString();
            myTAMoreDetail.PlanName = myDataTable.Rows[0]["PlanName"].ToString();
            myTAMoreDetail.PlanType = myDataTable.Rows[0]["PlanType"].ToString();
            myTAMoreDetail.CoverageLevel = myDataTable.Rows[0]["CoverageLevel"].ToString();
            myTAMoreDetail.Country = myDataTable.Rows[0]["Country"].ToString();
            myTAMoreDetail.Area = myDataTable.Rows[0]["Area"].ToString();
            myTAMoreDetail.Duration = myDataTable.Rows[0]["Duration"].ToString();
            myTAMoreDetail.StartDate = Convert.ToDateTime(myDataTable.Rows[0]["StartDate"].ToString());
            myTAMoreDetail.EndDate = Convert.ToDateTime(myDataTable.Rows[0]["EndDate"].ToString());
            myTAMoreDetail.ChildAge = Convert.ToInt32(myDataTable.Rows[0]["ChildAge"].ToString());
            myTAMoreDetail.AdultAge = Convert.ToInt32(myDataTable.Rows[0]["AdultAge"].ToString());
            myTAMoreDetail.NoOfTraveller = Convert.ToInt32(myDataTable.Rows[0]["NoOfTraveller"].ToString());

            myTAMoreDetail.TotalPremium = Convert.ToSingle(myDataTable.Rows[0]["TotalPremium"].ToString());
            myTAMoreDetail.PamentType = myDataTable.Rows[0]["PamentType"].ToString();
            myTAMoreDetail.ViewedDetailId = Convert.ToInt64(myDataTable.Rows[0]["ViewedDetailId"].ToString());            
            myTAMoreDetail.RowGUID = myDataTable.Rows[0]["RowGUID"].ToString();
            myTAMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myTAMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());

            if (myDataTable.Rows[0]["Info1"].ToString() != "")
                myTAMoreDetail.Info1 = myDataTable.Rows[0]["Info1"].ToString();
            else
                myTAMoreDetail.Info1 = "0";

            if (myDataTable.Rows[0]["Info2"].ToString() != "")
                myTAMoreDetail.Info2 = myDataTable.Rows[0]["Info2"].ToString();
            else
                myTAMoreDetail.Info2 = "0";

            if (myDataTable.Rows[0]["Info3"].ToString() != "")
                myTAMoreDetail.Info3 = myDataTable.Rows[0]["Info3"].ToString();
            else
                myTAMoreDetail.Info3 = "";

            return myTAMoreDetail;
        }
    }
}
